package com.lucher.mes.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 判断登录界面session失效
 */
public class BaseInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		if (request.getRequestURI() == null) {
			request.getRequestDispatcher("/mes/").forward(request, response);
			return false;
		}
		if (("/mes/").equals(request.getRequestURI())) {
			response.sendRedirect(request.getContextPath() + "/login");
			return false;
		}

		if (!(request.getRequestURI().endsWith("/mes/login")
				|| request.getRequestURI().endsWith("/mes/goLogin")
				|| request.getRequestURI().endsWith("/mes/logout")
				|| request.getRequestURI().endsWith("/mes/changeLanguage")
				|| request.getRequestURI().endsWith("/mes/noPermission")
				|| request.getRequestURI().indexOf("mes/js") > -1
				|| request.getRequestURI().indexOf("mes/layuiadmin") > -1
				|| request.getRequestURI().indexOf("mes/sale") > -1
				|| request.getRequestURI().indexOf("mes/style") > -1
				|| request.getRequestURI().indexOf("mes/images") > -1
				|| request.getRequestURI().indexOf("mes/httpForMps") > -1
				|| request.getRequestURI().indexOf("mes/httpForMachine") > -1
				|| request.getRequestURI().indexOf("mes/screanshow") > -1
				|| request.getRequestURI().indexOf("mes/xxq") > -1  //url 测试

				|| request.getRequestURI().indexOf("codearea") > -1)) {
			
			if (request.getSession().getAttribute("Operator") == null) {
				response.sendRedirect(request.getContextPath()+"/noPermission"); 
				return false;
			}
		}
		return super.preHandle(request, response, handler);
	}
}
